/*
promise wx.getSetting
*/
export const getSetting = () => {
    return new Promise((res,rej) => {
        wx.getSetting({
            success: (result)=>{
                res(result);
            },
            fail: (err)=>{
                rej(err)
            }
        });
    })
};


/*
promise wx.openSetting
*/
export const openSetting = () => {
    return new Promise((res,rej) => {
        wx.openSetting({
            success: (result)=>{
                res(result);
            },
            fail: (err)=>{
                rej(err)
            }
        });
    })
};


/*
promise wx.chooseAddress
*/
export const chooseAddress = () => {
    return new Promise((res,rej) => {
        wx.chooseAddress({
            success: (result)=>{
                res(result);                
            },
            fail: (err)=>{
                rej(err);
            }
        });
    })
};


/*
promise wx.showModal
参数为对象 例如：{content: "提示内容文字"}
*/
export const showModal = ({content}) => {
    return new Promise((res,rej) => {
        wx.showModal({
            title: '提示',
            content: content,
            success: (result) => {
                res(result)
            },
            fail: (err)=>{rej(err)},
            complete: ()=>{}
        });
    })
};


/*
promise wx.showToast
参数为对象 例如：{title: "提示内容文字"}
*/
export const showToast = ({title}) => {
    return new Promise((res,rej) => {
        wx.showToast({
            title: title,
            icon: 'none',
            mask: true,
            duration: 2000,
            success: (result)=>{
                res(result);
            },
            fail: ()=>{},
            complete: ()=>{}
        });
    })
};


/*
promise wx.getUserInfo
*/
export const getUserInfo = () => {
    return new Promise((res,rej) => {
        wx.getUserInfo({
            success: (result)=>{
                res(result);                
            },
            fail: (err)=>{ rej(err); }
        });
    })
};


/*
promise wx.login
*/
export const login = () => {
    return new Promise((res,rej) => {
        wx.login({
            timeout:10000,
            success: (result)=>{
                res(result); 
            },
            fail: (err)=>{ rej(err); }
          });
    })
};


/*
promise wx.requestPayment
参数类型为 对象
*/

export const requestPayment = (pay) => {
    return new Promise((res,rej) => {
        wx.requestPayment({
            ...pay,
            success: (result)=>{
              res(result)
            },
            fail: (err)=>{ rej(err); }
          });        
    })
};

